package com.sinothk.gpserver.modules.texasPoker.helper;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 编写 Liang Y.T.
 * 时间 2021/6/28 23:27
 */
public class Poker {

    String hua;
    String num;

    public String getHua() {
        return hua;
    }

    public void setHua(String hua) {
        this.hua = hua;
    }

    public String getNum() {
        return num;
    }

    public void setNum(String num) {
        this.num = num;
    }

    public Poker() {
        //养成写无参构造方法的习惯
    }

    public Poker(String hua, String num) {
        this.hua = hua;
        this.num = num;
    }

    public String toString() {
//        return "[" + hua + num + "]";
        return hua + num;
    }

    /**
     * 生成新牌
     *
     * @return
     */
    public static Poker[] getNewPoker() {
        Poker[] p = new Poker[52];
        String[] h = {"s", "c", "h", "d"}; // 黑、梅、红，方 "S", "C", "H", "D"
        String[] n = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "j", "q", "k", "a"};
        int c = 0;
        for (int k = 0; k < 13; k++) {
            for (int j = 0; j < 4; j++) {
                p[c] = new Poker(h[j], n[k]);
                c++;
            }
        }
        return p;
    }

    /**
     * 生成新牌
     *
     * @return
     */
    public static Poker[] getNewPoker7s() {
        Poker[] p = new Poker[28];
        String[] h = {"s", "c", "h", "d"}; // 黑、梅、红，方 "S", "C", "H", "D"
        String[] n = {"8", "9", "10", "j", "q", "k", "a"};
        int c = 0;
        for (int k = 0; k < 7; k++) {
            for (int j = 0; j < 4; j++) {
                p[c] = new Poker(h[j], n[k]);
                c++;
            }
        }
        return p;
    }

    public static Poker[] getEnablePoker(Poker[] p) {
        //利用随机交换进行洗牌
        for (int k = 0; k < p.length; k++) {
            int a = (int) (Math.random() * 52);//0~51
            if (!p[k].equals(p[a])) {
                Poker temp = p[k];
                p[k] = p[a];
                p[a] = temp;
            }
        }
        return p;
    }

    public static Poker[] getEnablePoker() {
        Poker[] p = getNewPoker();

        //利用随机交换进行洗牌
        for (int k = 0; k < p.length; k++) {
            int a = (int) (Math.random() * 52);//0~51
            if (!p[k].equals(p[a])) {
                Poker temp = p[k];
                p[k] = p[a];
                p[a] = temp;
            }
        }
        return p;
    }

    public static Poker[] getEnablePokerFor7s(int roomType) {
        Poker[] p = null;
        if (roomType == 0) {
            p = getNewPoker();
            //利用随机交换进行洗牌
            for (int k = 0; k < p.length; k++) {
                int a = (int) (Math.random() * 52);//0~51
                if (!p[k].equals(p[a])) {
                    Poker temp = p[k];
                    p[k] = p[a];
                    p[a] = temp;
                }
            }
        } else{
            p = getNewPoker7s();
            //利用随机交换进行洗牌
            for (int k = 0; k < p.length; k++) {
                int a = (int) (Math.random() * 28);//0~27
                if (!p[k].equals(p[a])) {
                    Poker temp = p[k];
                    p[k] = p[a];
                    p[a] = temp;
                }
            }
        }
        return p;
    }

}
